package org.fastdfs.test.fastdfsye.controller;

import org.csource.common.MyException;
import org.fastdfs.test.fastdfsye.utils.UploadUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
import java.util.HashMap;
@Controller
@RequestMapping("/img")
public class con {
    @Autowired
    public UploadUtils uploadUtils;
    @RequestMapping("/upload")
    public String upload(@RequestParam("file") MultipartFile file) throws IOException, MyException {
        HashMap<String, String> map = new HashMap<>();
        map.put("name","sd");
        System.out.println("跨域成功");
        String url = uploadUtils.upload(file.getBytes(), "jpeg", map);
        System.out.println(url);
        return url;
    }
    @RequestMapping("/delete")
    public void delete(String url) throws IOException, MyException {
        uploadUtils.delete(url);
    }
}
